package com.easwift.qsp.das;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

import com.easwift.qsp.das.cjy.CJYSocketReadThread;
import com.easwift.qsp.das.cjy.CJYSocketWriteThread;
import com.easwift.qsp.das.xgy.XGSocketWriteThread;
import com.easwift.qsp.das.xgy.XGYSocketReadThread;
import com.easwift.qsp.das.dvw16.DVWSocketReadThread;
import com.easwift.qsp.das.dvw16.DVWSocketWriteThread;
import com.easwift.qsp.das.dyy.DYYSocketReadThread;
import com.easwift.qsp.das.qjy.QJYSocketReadThread;
import com.easwift.qsp.das.qjy.QJYSocketWriteThread;
import com.easwift.qsp.das.szy.SZYSocketReadThread;
import com.easwift.qsp.das.szy.SZYSocketWriteThread;

public class SocketThread extends Thread{

	private Socket socket;


	public SocketThread(Socket socket) {
		super();
		this.socket = socket;


	}

	@Override
	public void run(){
		//加入线程唯一的id，不能重复
		Test.socketThreadSet.add(this.getId());
		//获取所使用的接口
		int port = socket.getLocalPort();
		try{
			InputStream in = socket.getInputStream();
			BufferedInputStream bis = new BufferedInputStream(in);
			OutputStream os = socket.getOutputStream();
			BufferedOutputStream bos = new BufferedOutputStream(os);

			//TODO port从平台中读取
			if(port == 8083){
				new DVWSocketReadThread(bis).start();
				new DVWSocketWriteThread(bos).start();
			}else if(port == 8081){
				new SZYSocketReadThread(bis).start();
				new SZYSocketWriteThread(bos).start();
			}else if(port == 8091){
				new CJYSocketReadThread(bis).start();
				new CJYSocketWriteThread(bos).start();
			} else if(port == 8092){
				new QJYSocketReadThread(bis).start();
				new QJYSocketWriteThread(bos).start();
			}else if(port == 8080){
				new DYYSocketReadThread(bis).start();
			}else if (port== 8090){
				new XGYSocketReadThread(bis,this.getId()).start();
				new XGSocketWriteThread(bos,this.getId()).start();
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}

}
